//
//  SNAssociatorViewController.m
//  ZhuoxinAgriculture
//
//  Created by stone on 16/12/16.
//  Copyright © 2016年 stone. All rights reserved.
//

#import "SNFarmViewController.h"
#import "SNDetailInfoCell.h"
@interface SNFarmViewController ()<UITableViewDataSource,UITableViewDelegate>
/** tableView */
@property (nonatomic,weak) UITableView * tableView;

@end

@implementation SNFarmViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"详细信息";
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    CGRect frame = CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64);
    UITableView * tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
    self.tableView = tableView;
    [self setupInit:tableView];
    
    [self.view addSubview:tableView];
    
    [self addObserver];
    [self addRequest];
}
#pragma mark - <addRequest>
- (void)addRequest {
    // addRequest
    
    //    [[ZXHTTPManager sharedManager] getUserInfoWithUserId:self.USERID certNo:nil completed:^(NSDictionary *jsonDict, NSError *error) {
    //
    //        logError;
    //
    //        if([jsonDict[@"status"] integerValue] == 1){
    //            // 失败
    //            NSLog(@"%@",jsonDict[@"message"]);
    //            [SNProgressManager showToView:self.view message:jsonDict[@"message"] afterDelay:2];
    //            return ;
    //        };
    //        NSLog(@"%@",jsonDict);
    //        NSDictionary * dict = jsonDict[@"result"][0];
    //        ZXUserDetailInfo * userDetailInfo = [ZXUserDetailInfo mj_objectWithKeyValues:dict];
    //
    //        self.userDetailInfo = userDetailInfo;
    //
    //        [self.tableView reloadData];
    //
    //    }];
    
}
#pragma mark - <addObserver>
- (void)addObserver {
    // addObserver
}
- (void)dealloc {
    NSLog(@"%@ %s %@",[self class], __func__ , @"im dying");
}

- (void)setupInit:(UITableView *)tableView {
    tableView.delegate = self;
    tableView.dataSource = self;
    //    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 10)];
    //    headerView.backgroundColor = HexRGB(0xf5f5f5);
    //    tableView.tableHeaderView = headerView;
    tableView.backgroundColor = HexRGB(0xf5f5f5);
    //    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.separatorInset = UIEdgeInsetsZero;
    tableView.tableFooterView = [UIView new];
    [self setHeights:tableView];
    [self registerNib:tableView];
    [self registerClass:tableView];
}
#pragma mark - <Register>
/** registerNib */
- (void)registerNib:(UITableView *)tableView {
    [tableView registerNib:[UINib nibWithNibName:NSStringFromClass([SNDetailInfoCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([SNDetailInfoCell class])];
}
/** registerClass */
- (void)registerClass:(UITableView *)tableView {
    //    [tableView registerClass:[SNTableViewCell class] forCellReuseIdentifier:NSStringFromClass([SNTableViewCell class])];
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
    //    [tableView registerClass:[UITableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:NSStringFromClass([UITableViewHeaderFooterView class])];
}
#pragma mark - <SetHeights>
/** setHeights */
- (void)setHeights:(UITableView *)tableView {
    
    /** header */
    tableView.sectionHeaderHeight = 10;
    // tableView.estimatedSectionHeaderHeight = 100;
    // tableView.sectionHeaderHeight = UITableViewAutomaticDimension;
    /** cell */
    tableView.estimatedRowHeight = 47;
    tableView.rowHeight = UITableViewAutomaticDimension;
    /** footer */
    tableView.sectionFooterHeight = 0.001;
    // tableView.estimatedSectionFooterHeight = 100;
    // tableView.sectionFooterHeight = UITableViewAutomaticDimension;
}

#pragma mark - <UITableViewDataSource>
/** 组数 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 2;
}
/** 行数 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    if (section == 0) {
        return 3;
    }else{
        return 2;
    }
}
//MARK: -
//MARK: - cell
/** cell */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    SNDetailInfoCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SNDetailInfoCell class])];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    
    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case 0:
                [cell configCellWithKeyString:@"农场名称" valueString:kFileterString(self.model.fullName)];
                break;
            case 1:
                [cell configCellWithKeyString:@"所在地区" valueString:kFileterString(self.model.filteredAddress)];
                break;
            case 2:
                [cell configCellWithKeyString:@"组织机构代码" valueString:kFileterString(self.model.orgCode)];
                break;
            default:
                break;
        }
    }else{
        switch (indexPath.row) {
            case 0:
                [cell configCellWithKeyString:@"姓名" valueString:kFileterString(self.model.legalName)];
                break;
            case 1:
                [cell configCellWithKeyString:@"手机号码" valueString:kFileterString(self.model.legalPhone)];
                break;
            default:
                break;
        }
    }
    
    
    return cell;
}
#pragma mark - <UITableViewDelegate>
/** 选中一行 */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%s", __func__);
    //    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
/** 取消 选中 */
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0) {
    NSLog(@"%s", __func__);
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return 0.001;
}

@end
